home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Special 25
/
AMIGAplus Sonderheft 25 (2000)(Falke)(DE)(Track 1 of 4)[!].iso
/
PublicDomain
/
Anwendungen
/
Lunar
/
Original
/
lunar.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-06-21
|
23KB
|
838 lines
char version[] = "Lunar Version 2.0 (June 20, 1991)";
/*----------------------------------------------------------------------------
Lunar 2.0: A Calendar Conversion Program
for
Gregorian Solar Calendar and Chinese Lunar Calendar
---------------------------------------------------
By Fung F. Lee and Ricky Yeung
Copyright (C) 1988,1989,1991 Fung F. Lee and Ricky Yeung
All rights reserved.
Permission to copy and distribute verbatim copies of this
document for non-commercial purposes is granted, but changing
it is not allowed.
There is absolutely no warranty for this program.
Please send your comments and suggestions to the authors:
Fung F. Lee lee@milo.stanford.edu
Ricky Yeung yeung@decwrl.dec.com or yeung@atd.dec.com
The special "bitmap" file "lunar.bitmap" was contributed
by Weimin Liu (weimin@alpha.ece.jhu.edu).
----------------------------------------------------------------------------*/
/*
This document contains Highest-bit-set GuoBiao (HGB) code, as adopted by
CCDOS on IBM PC compatibles, ChineseTalk 6.0 (GB version) on Macintosh,
and cxterm on UNIX and X window. Hence, one may need to transfer this
document as a **binary** file.
References:
1. "Zhong1guo2 yin1yang2 ri4yue4 dui4zhao4 wan4nian2li4" by Lin2 Qi3yuan2.
¡¶ÖйúÒõÑôÈÕÔ¶ÔÕÕÍòÄêÀú¡·£®ÁÖ
2. "Ming4li3 ge2xin1 zi3ping2 cui4yan2" by Xu2 Le4wu2.
¡¶ÃüÀí¸ïÐÂ×Óƽ´âÑÔ¡·£®Ðì
*/
#include <stdio.h>
#include <string.h>
/* "Bitmap" constants */
#define BMRow 7 /* number of rows for each bitmap */
#define BMCol 11 /* number of columns for each bitmap */
#define NBM 26 /* number of bitmaps */
#define NianBM 0
#define YueBM 1
#define RiBM 2
#define ShiBM 3
#define GanBM 4
#define ZhiBM 14
#define Cyear 1900 /* Note that LC1900.1.1 is SC1900.1.31 */
#define Nyear 101 /* number of years covered by the table */
#define Nmonth 13 /* maximum number of months in a lunar year */
typedef struct {
int year, month, day, hour, weekday;
int leap; /* the lunar month is a leap month */
} Date;
static Date SolarFirstDate = {
/* Wednesday, 12 a.m., 31 January, 1900 */
1900, 1, 31, 0, 3, 0
};
static Date LunarFirstDate = {
/* Wednesday, 12 a.m., First day, First month, 1900 */
1900, 1, 1, 0, 3, 0
};
static Date GanFirstDate = {
/* geng1-nian2 wu4-yue4 jia3-ri4 jia3-shi2 */
6, 4, 0, 0, 3, 0
};
static Date ZhiFirstDate = {
/* zi3-nian2 yin2-yue4 chen2-ri4 zi3-shi2 */
0, 2, 4, 0, 3, 0
};
static int daysInSolarMonth[13] = {
0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
static int moon[2] = {29,30}; /* a short (long) lunar month has 29 (30) days */
static long yearInfo[Nyear] = {
/* encoding:
b bbbbbbbbbbbb bbbb
bit# 1 111111000000 0000
6 543210987654 3210
. ............ ....
month# 000000000111
M 123456789012 L
b_j = 1 for long month, b_j = 0 for short month
L is the leap month of the year if 1<=L<=12; NO leap month if L = 0.
The leap month (if exists) is long one iff M = 1.
*/
0x04bd8, /* 1900 */
0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, /* 1905 */
0x16554, 0x056a0, 0x09ad0, 0x055d2, 0x04ae0, /* 1910 */
0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, /* 1915 */
0x0d6a0, 0x0ada2, 0x095b0, 0x14977, 0x04970, /* 1920 */
0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, /* 1925 */
0x02b60, 0x09570, 0x052f2, 0x04970, 0x06566, /* 1930 */
0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, /* 1935 */
0x186e3, 0x092e0, 0x1c8d7, 0x0c950, 0x0d4a0, /* 1940 */
0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4, 0x025d0, /* 1945 */
0x092d0, 0x0d2b2, 0x0a950, 0x0b557, 0x06ca0, /* 1950 */
0x0b550, 0x15355, 0x04da0, 0x0a5d0, 0x14573, /* 1955 */
0x052d0, 0x0a9a8, 0x0e950, 0x06aa0, 0x0aea6, /* 1960 */
0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, /* 1965 */
0x0f263, 0x0d950, 0x05b57, 0x056a0, 0x096d0, /* 1970 */
0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, /* 1975 */
0x0d558, 0x0b540, 0x0b5a0, 0x195a6, 0x095b0, /* 1980 */
0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, /* 1985 */
0x06d40, 0x0af46, 0x0ab60, 0x09570, 0x04af5, /* 1990 */
0x04970, 0x064b0, 0x074a3, 0x0ea50, 0x06b58, /* 1995 */
0x055c0, 0x0ab60, 0x096d5, 0x092e0, 0x0c960 /* 2000 */
};
/*
In "4-column" calculation, a "mingli" (fortune-telling) calculation,
the beginning of a month is not the first day of the month as in
the Lunar Calendar; it is instead governed by "jie2" (festival).
Interestingly, in the Solar calendar, a jie always comes within three
days after some fixed date. For example, the jie "li4chun1" (beginning
of spring) always comes within three days after Feburary 4 of the Solar
Calendar. This is true at least for the years between 1900 and 2000.
The table may need to be adjusted if exceptions are found when
the range is extended.
Meaning of array jie:
For example, the first integer 4 means the beginning of the 1st month
is no earlier than Feburary 4; the 12th integer 5 means the beginning of
the 12th month is no earlier than January 5 (of the next Solar year) in
the Solar Calendar.
Meaning of array fest:
Each 24 bit number represents the offsets of the 12 jie's of the year
from the reference days in jie[]. For example, the number corresponding to
the "Lunar Year" 1991 is 0x154551, and the two least significant bits
(bit-1, bit-0) are 01. This means that the first day of the 12th month of
the "Lunar Year" 1991 falls on January 6, 1992, one day after the reference
date January 5 as in jie[]. (Incidentally, the first day of that lunar month
is on January 5.)
*/
short jie[] = {4, 5, 4, 5, 5, 7, 7, 7, 8, 7, 7, 5};
long fest[Nyear] = {
0x154551, /* 1900 */
0x155555, 0x599555, 0x6a9a56, 0x554551, 0x155555, /* 1905 */
0x595555, 0x6a9a56, 0x554551, 0x155555, 0x595555, /* 1910 */
0x6a9a56, 0x554551, 0x155555, 0x155555, 0x599655, /* 1915 */
0x554511, 0x155551, 0x155555, 0x599655, 0x554511, /* 1920 */
0x155561, 0x155555, 0x599655, 0x554511, 0x155551, /* 1925 */
0x155555, 0x599555, 0x554501, 0x154551, 0x155555, /* 1930 */
0x599555, 0x554501, 0x154551, 0x155555, 0x595555, /* 1935 */
0x554501, 0x154551, 0x155555, 0x595555, 0x554501, /* 1940 */
0x154551, 0x155555, 0x595555, 0x544501, 0x154511, /* 1945 */
0x155555, 0x155555, 0x444100, 0x154511, 0x155555, /* 1950 */
0x155555, 0x444100, 0x154511, 0x155551, 0x155555, /* 1955 */
0x444100, 0x154511, 0x154551, 0x155555, 0x444000, /* 1960 */
0x154501, 0x154551, 0x155555, 0x444000, 0x154501, /* 1965 */
0x154551, 0x155555, 0x440000, 0x154501, 0x154551, /* 1970 */
0x155555, 0x440000, 0x144501, 0x154551, 0x155555, /* 1975 */
0x400000, 0x144101, 0x154511, 0x155555, 0x400000, /* 1980 */
0x144101, 0x154511, 0x155555, 0x0, 0x44100, /* 1985 */
0x154511, 0x154551, 0x0, 0x44000, 0x154511, /* 1990 */
0x154551, 0x0, 0x44000, 0x154501, 0x154551, /* 1995 */
0x0, 0x40000, 0x154501, 0x154551, 0x0 /* 2000 */
};
static char *Gan[] = {
"Jia3", "Yi3", "Bing3", "Ding1", "Wu4",
"Ji3", "Geng1", "Xin1", "Ren2", "Gui3"
};
static char *Zhi[] = {
"Zi3", "Chou3", "Yin2", "Mao3", "Chen2", "Si4",
"Wu3", "Wei4", "Shen1", "You3", "Xu1", "Hai4"
};
static char *ShengXiao[] = {
"Mouse", "Ox", "Tiger", "Rabbit", "Dragon", "Snake",
"Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig"
};
static char *weekday[] = {
"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"
};
static char *GanGB[] = {
"¼×", "ÒÒ", "±û", "¶¡", "Îì",
"¼º", "¸ý", "ÐÁ", "ÈÉ", "¹ï"
};
static char *ZhiGB[] = {
"×Ó", "³ó", "Òú", "î", "³½", "ËÈ",
"Îç", "δ", "Éê", "ÓÏ", "Ðç", "º¥"
};
static char *ShengXiaoGB[] = {
"Êó", "Å£", "»¢", "ÍÃ", "Áú", "Éß",
"Âí", "Ñò", "ºï", "¼¦", "¹·", "Öí"
};
static char *weekdayGB[] = {
"ÈÕ", "Ò»", "¶þ", "Èý",
"ËÄ", "Îå", "Áù"
};
Date solar, lunar, gan, zhi, gan2, zhi2, lunar2;
int ymonth[Nyear]; /* number of lunar months in the years */
int yday[Nyear]; /* number of lunar days in the years */
int mday[Nmonth+1]; /* number of days in the months of the lunar year